<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>实时投票系统</title>
    <style>
        body {
            font-family: 'Arial', sans-serif;
            max-width: 600px;
            margin: 0 auto;
            padding: 20px;
            text-align: center;
            background-color: #f5f5f5;
        }
        h1 {
            color: #333;
        }
        .vote-container {
            background-color: white;
            border-radius: 10px;
            padding: 20px;
            box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
            margin-top: 20px;
        }
        .option {
            display: flex;
            align-items: center;
            margin: 15px 0;
            padding: 10px;
            border-radius: 5px;
            transition: background-color 0.3s;
            cursor: pointer;
        }
        .option:hover {
            background-color: #f0f0f0;
        }
        input[type="radio"] {
            margin-right: 15px;
            transform: scale(1.3);
            cursor: pointer;
        }
        .option-label {
            flex-grow: 1;
            text-align: left;
            font-size: 18px;
            cursor: pointer;
        }
        .vote-count {
            font-weight: bold;
            color: #2c3e50;
            min-width: 40px;
            text-align: right;
        }
        .progress-bar {
            height: 20px;
            background-color: #ecf0f1;
            border-radius: 10px;
            margin-top: 5px;
            overflow: hidden;
        }
        .progress {
            height: 100%;
            background-color: #3498db;
            transition: width 0.5s;
        }
        .total-votes {
            margin-top: 20px;
            font-style: italic;
            color: #7f8c8d;
        }
    </style>
</head>
<body>
    <h1>请选择你喜欢的选项</h1>
    
    <div class="vote-container">
        <div class="option">
            <input type="radio" name="vote" id="option1" onchange="handleVote('option1')">
            <label for="option1" class="option-label">选项一</label>
            <span class="vote-count" id="count1">0</span>
        </div>
        <div class="progress-bar">
            <div class="progress" id="progress1"></div>
        </div>
        
        <div class="option">
            <input type="radio" name="vote" id="option2" onchange="handleVote('option2')">
            <label for="option2" class="option-label">选项二</label>
            <span class="vote-count" id="count2">0</span>
        </div>
        <div class="progress-bar">
            <div class="progress" id="progress2"></div>
        </div>
        
        <div class="total-votes">总票数: <span id="total">0</span></div>
    </div>

    <script>
        // 初始化投票数据
        let votes = {
            option1: 0,
            option2: 0
        };
        
        // 存储用户当前选择（用于改票功能）
        let userVote = null;
        
        // 处理投票逻辑（现在只通过onchange触发）
        function handleVote(option) {
            // 如果是改票，先减少原选项的票数
            if (userVote && userVote !== option) {
                votes[userVote]--;
            }
            
            // 更新用户当前选择
            userVote = option;
            
            // 增加新选项的票数
            votes[option]++;
            
            // 更新UI
            updateVoteDisplay();
        }
        
        // 更新投票显示
        function updateVoteDisplay() {
            const total = votes.option1 + votes.option2;
            
            // 更新票数显示
            document.getElementById('count1').textContent = votes.option1;
            document.getElementById('count2').textContent = votes.option2;
            document.getElementById('total').textContent = total;
            
            // 更新进度条
            if (total > 0) {
                const percent1 = (votes.option1 / total) * 100;
                const percent2 = (votes.option2 / total) * 100;
                document.getElementById('progress1').style.width = percent1 + '%';
                document.getElementById('progress2').style.width = percent2 + '%';
            } else {
                document.getElementById('progress1').style.width = '0%';
                document.getElementById('progress2').style.width = '0%';
            }
        }
        
        // 初始化
        updateVoteDisplay();
    </script>
</body>
</html>